/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package Koneksi;

/**
 *
 * @author user
 */

import java.sql.*;
import oracle.jdbc.OracleDriver;

public class Koneksi {

//    private String jdbcURL = "jdbc:Oracle:thin:@172.23.9.185:1521:orcl";
//    private String user = "MHS105314003";
//    private String password = "MHS105314003";
    
//    public static String jdbcURL = "jdbc:oracle:thin:@localhost:1521:xe";
//    public static String user = "root";
//    public static String password = "";
    
    private String jdbcURL = "jdbc:mysql://localhost:3306/rplt";
    private String user = "root";
    private String password = "";
    private Connection connection = null;

    public Koneksi() {
        try {
//            DriverManager.registerDriver(new OracleDriver());
            DriverManager.registerDriver(new OracleDriver());
            connection = DriverManager.getConnection(jdbcURL, user, password);
            System.out.println("koneksi berhasil");
        } catch (Exception ex) {
            System.out.println("message: " + ex.getMessage());
        }
    }

    public boolean isConnected() {
        if (connection != null) {
            return true;
        } else {
            return false;
        }
    }

    public boolean getClosed() {
        if (isConnected()) {
            try {
                connection.close();
                connection = null;
            } catch (SQLException ex) {
                ex.printStackTrace();
            }
            return true;
        } else {
            return false;
        }
    }

    public String getJdbcURL() {
        return jdbcURL;
    }

    public void setJdbcURL(String jdbcURL) {
        this.jdbcURL = jdbcURL;
    }

    public String getUser() {
        return user;
    }

    public void setUser(String user) {
        this.user = user;
    }

    public String getPassword() {
        return password;
    }

    public void setPassword(String password) {
        this.password = password;
    }

    public Connection getConnection() {
        return connection;
    }

    public void setConn(Connection connection) {
        this.connection = connection;
    }



    public static void main(String[] args) {

        Koneksi conn = new Koneksi();
        try {
            String query = "select * from pinjam";
            Statement statement = conn.getConnection().createStatement();
            ResultSet result = statement.executeQuery(query);

//            while (result.next()) {
//                System.out.println("judul buku : " + result.getString("judulBuku"));
//                System.out.println("Nim : " + result.getString("NIM"));
//            }

            statement.close();
        } catch (Exception ex) {
            System.out.println("message: " + ex.getMessage());
        }

    }
}
